package com.example.bookshop.controller.user;

import com.example.bookshop.entity.BaseOrder;
import com.example.bookshop.entity.Order;
import com.example.bookshop.repository.OrderRepository;
import com.example.bookshop.result.Result;
import com.example.bookshop.service.user.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@CrossOrigin
public class OrderController {
    @Autowired
    OrderService orderService;
    //添加订单
    @RequestMapping("api/addOrder")
    public Result addOrder(@RequestBody Order order, HttpSession session){
          return orderService.addOrder(order,session);
    }
    //查询订单基本信息
    @RequestMapping("api/getListOrder")
    public List<BaseOrder> getListOrder(HttpSession session){
        return orderService.getListOrder(session);
    }
    //获取详细订单
    @RequestMapping("api/orderDetail")
    public Order OrderDetail(@RequestBody Order order){
        return orderService.OrderDetail(order.getId());
    }
    //发货
    @RequestMapping("api/deliverGoods")
    public Result deliverGoods(@RequestBody Order order){
        return orderService.deliverGoods(order);
    }
    //获取用户的订单
    @RequestMapping("api/getUserOrder")
    public List<BaseOrder>getUserOrder(HttpSession session){
        return orderService.getUserOrder(session);
    }
    //确认收货
    @RequestMapping("api/confirmOrder")
    public Result confirmOrder(@RequestBody Order order){
        return orderService.confirmOrder(order.getId());
    }
}
